package com.ziytek.web.citizen.util;

import lombok.extern.slf4j.Slf4j;

import java.io.File;

/**
 * @className LocationUtils
 * @description: 描述
 * @jdkVersion: 1.8
 * @author: fhx
 * @date: 2024/7/2 9:53
 */
@Slf4j
public class LocationUtils {

    public static String getLocation() {
        return System.getProperty("user.dir");
        //return System.getProperty("user.dir") + "\\app";
    }


    public static void downloadLocation(String cabinetNo, String beginTimeStr) {
        String downloadPath = getLocation() + "/download";
        String downloadCabinetPath = getLocation() + "/download/" + cabinetNo;
        File folder = new File(downloadPath);
        if (!folder.exists()) {
            log.info("The download folder does not exist, create folder:{}", downloadPath);
            folder.mkdir();
        }

        File folderDownloadCabinet = new File(downloadCabinetPath);
        if (!folderDownloadCabinet.exists()) {
            log.info("The download folder does not exist, create folder:{}", downloadCabinetPath);
            folderDownloadCabinet.mkdir();
        }

        String location = downloadLocationPath(cabinetNo, beginTimeStr);
        File folderLocation = new File(location);
        if (!folderLocation.exists()) {
            log.info("The download folder does not exist, create folder:{}", location);
            folderLocation.mkdir();
        }
    }

    public static String downloadLocationPath(String cabinetNo, String beginTimeStr) {
        beginTimeStr = beginTimeStr.replace(":", "")
                .replace("-", "")
                .replace(" ", "");
        return getLocation() + "/download/" + cabinetNo + "/" + beginTimeStr;
    }
}
